package com.symria.taglib;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.jsp.JspException;

import org.apache.cxf.binding.corba.wsdl.Const;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.views.jsp.StrutsBodyTagSupport;

import com.symria.framework.constant.ATTFrameWork;
import com.symria.framework.util.SpringUtil;
import com.symria.framework.util.StringUtil;
import com.symria.role.util.Logger;
import com.symria.server.bo.role.RoleService;
import com.symria.server.po.Constant;


public class ConstantsName extends StrutsBodyTagSupport {
	private static final Logger logger = Logger.getLogger(ConstantsName.class);
    private String value;
    private String codename;
    private String code;
    private RoleService roleService;
    

	@Override
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}
	@Override
	public int doStartTag() throws JspException {
		roleService = SpringUtil.getBean("roleService",RoleService.class);
	    try {
	    	Constant c = roleService.findConstantByCode(code);
			pageContext.getOut().write(c==null?"":c.getContsName());
		} catch (IOException e) {
			logger.logError("constants tag error:"+e.getMessage());
		}
		return EVAL_BODY_BUFFERED;
	}
	public String createOptions(List<Constant> list){
		StringBuffer sBuf = new StringBuffer();
		for(Constant conts:list){
			sBuf.append("<option value=\""+conts.getCode()+"\"");
			if(StringUtil.equals(conts.getCode(),value)){
				sBuf.append("selected=\"selected\"");
			}
			sBuf.append(">");
			sBuf.append(conts.getContsName());
			sBuf.append("</option>");
		}
		return sBuf.toString();
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getCodename() {
		return codename;
	}
	public void setCodename(String codename) {
		this.codename = codename;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
    
}
